﻿// ===============================================================================
// Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
// ===============================================================================

using System;
using XCI.Extensions;
using XCI.Helper;
using XCI.Sys.Service;
using XCI.Windows;

namespace XCI.Sys.Forms
{
    /// <summary>
    /// 系统单个字典管理
    /// </summary>
    [FormCaption("系统单个字典管理")]
    public partial class FrmSingleDicManager : BaseForm
    {
        public FrmSingleDicManager()
        {
            InitializeComponent();
        }

        private async void FrmSingleDicManager_Load(object sender, EventArgs e)
        {
            if (Args.TryGetValue("code", out string code) && code.IsNotEmpty())
            {
                var model = await SysDicService.Instance.SelectDicCategoryByCodeAsync(code);
                if (model != null)
                {
                   await dicDetailsManagerControl1.SetCategoryAsync(model);
                }
                else
                {
                    ShowInvalidCodeMessage();
                }
            }
            else
            {
                ShowInvalidCodeMessage();
            }
        }

        private void ShowInvalidCodeMessage()
        {
            MessageBoxHelper.ShowError("请指定正确的字典编码，参数名：code");
        }
    }
}